cmake_minimum_required(VERSION 3.5)

project(testai VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)


find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)

include_directories(${CMAKE_SOURCE_DIR})


set(PROJECT_SOURCES
        main.cpp
        mainwindow.cpp
        mainwindow.h
        mainwindow.ui
        learnRole.h
        learnRole.cpp

)
# 瀹氫箟椤圭洰婧愭枃浠跺垪琛�

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(testai
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
    )
    # 濡傛灉Qt鐗堟湰澶т簬绛変簬6锛屽垯浣跨敤qt_add_executable娣诲姞鍙墽琛屾枃浠讹紝鎵嬪姩澶勭悊鏈€缁堝寲姝ラ
else()
    if(ANDROID)
        add_library(testai SHARED
            ${PROJECT_SOURCES}
        )
        # 濡傛灉Qt鐗堟湰灏忎簬6涓旀槸Android骞冲彴锛屽垯娣诲姞涓€涓叡浜簱
    else()
        add_executable(testai
            ${PROJECT_SOURCES}
        )
        # 鍚﹀垯锛屾坊鍔犱竴涓彲鎵ц鏂囦欢
    endif()
endif()

target_link_libraries(testai PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
# 閾炬帴Qt鐨刉idgets搴撳埌鐩爣testai

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
  set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.testai)
endif()
# 濡傛灉Qt鐗堟湰灏忎簬6.1.0锛屽垯璁剧疆bundle鏍囪瘑绗﹂€夐」

set_target_properties(testai PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)
# 璁剧疆鐩爣testai鐨勫睘鎬э紝鍖呮嫭bundle鏍囪瘑绗︼紝bundle鐗堟湰锛岀煭鐗堟湰瀛楃涓诧紝浠ュ強璁剧疆涓簃acOS鍜學indows鍙墽琛屾枃浠�

include(GNUInstallDirs)
install(TARGETS testai
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
# 鍖呭惈GNU鏍囧噯瀹夎鐩綍锛屽苟瀹夎鐩爣testai锛屽垎鍒寚瀹歜undle銆佸簱鍜岃繍琛屾椂鏂囦欢鐨勫畨瑁呰矾寰�

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(testai)
endif()
# 濡傛灉Qt鐗堟湰涓�6锛屽垯瀵圭洰鏍噒estai杩涜鏈€缁堝寲澶勭悊TIME DESTINATION ${CMAKE_INSTALL_BINDIR}


# 濡傛灉浣跨敤鐨勬槸 Qt 6锛屽垯璋冪敤 qt_finalize_executable 瀹屾垚鍙墽琛屾枃浠剁殑鏈€缁堝寲
if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(testai)
endif()